package handlers;


/**
 * <p>Title: BaseTask.java</p>
 * <p>Description: </p>
 * <p>Company: www.huoyunren.com</p>
 * @author duanxiangyun
 * @date 2015年8月6日
 * @version 1.0
 */

import java.util.Date;
import java.util.Map;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import com.duan.test.utils.common.CommonUtils;
import com.hxbd.test.utils.InterfaceUtils;
import com.hxbd.test.utils.MsgSend;

public class BaseTask extends InterfaceUtils {

	// 修改该参数作为默认测试环境，在进行调试或者testNG.xml没有传环境参数时默认为该值
	protected static final String ttype = "interface";
	protected static final String env = "test";
	protected static final String level = "1";

	@Parameters({"testEnv" ,"level","testtype"})
	@BeforeSuite(alwaysRun = true)
	protected void beforeSuite(ITestContext context,@Optional(env) String testEnv,@Optional(level) String testlevel,@Optional(ttype) String testtype) {
		if (isStrEmpty(testEnv)) {
			Assert.fail("请在testNG配置文件中设置测试环境testEnv");
		}
		setTesttype(testtype);
		test_Env = testEnv.trim();
//		初始化数据
//		initTestData(testEnv);
		initExtent(testEnv,"jiedian_接口测试_" + testEnv + "环境");
		setTlevel(testlevel);
	}

	@Parameters({ "testEnv" })
	@AfterSuite
	protected void afterSuite(@Optional(env) String testEnv) {
//		delTestData(testEnv);
		endtest();
		extent.flush();
	}

	@BeforeGroups(value = "107015090000007", alwaysRun = true)
	protected void beforeGroup4() {
		// 发送报文
		  if(test_Env.equalsIgnoreCase("test")) {
				MsgSend msg = new MsgSend();
				Map<Integer, Date> tmpmap = msg.sendMsg(
						"172.22.34.237",
						16531,
						CommonUtils.getFilePath("/TestData/" + test_Env + "/msg/"
								+ "Msg_Smart1.txt"), now("yy MM dd HH mm ss"), 10);
				put(msg_map, "smart", tmpmap);  
		    }
		   else if (test_Env.equalsIgnoreCase("product")) {
		MsgSend msg = new MsgSend();
		Map<Integer, Date> tmpmap = msg.sendMsg(
				"118.178.33.51",
				9001,
				CommonUtils.getFilePath("/TestData/" + test_Env + "/msg/"
						+ "Msg_Smart1.txt"), now("yy MM dd HH mm ss"), 10);
		put(msg_map, "smart", tmpmap);
		   }
	}
}
